<template>
  <div class="about">
    <el-container>
      <el-header>
        <div class="home">
          <!-- <img src="../../public/20250416095642.png" alt="" /> -->
          <span style="color: #fff">vue试练</span>
        </div>
        <!-- <div> -->
        <div>
          <el-button type="info" round>信息按钮</el-button>
          <!-- </div> -->
        </div>
      </el-header>
      <el-container>
        <el-aside :width="isCollapse ? '60px' : '200px'">
          <div class="toggle-button" @click="toggle">|||</div>
          <el-menu
            :router="true"
            background-color="#3c3c3c"
            text-color="#fff"
            active-text-color="#359BFF"
            :unique-opened = 'true'
            :collapse="isCollapse"
            :collapse-transition="false"
            :default-active="path"
          >

            <el-submenu
              :index="item.id + ''"
              v-for="item in meunlist"
              :key="item.id"
            >
              <template slot="title">
                <i :class="iconsobj[item.id]"></i>
                <span>{{ item.authName }}</span>
              </template>
              <el-menu-item
                :index="'/' + item.path"
                v-for="item in item.children"
                :key="item.id"
                @click="saveNavState('/' + item.path)"
              >
                <template slot="title">
                  <i class="el-icon-menu"></i>
                  <span>{{ item.authName }}</span>
                </template>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
import { MenulistApi } from '../api/index'
export default {
  created () {
    this.getMenulist()
    this.path = window.sessionStorage.getItem('navState')
  },
  data () {
    return {
      meunlist: [],
      iconsobj: {
        125: 'el-icon-user-solid',
        103: 'el-icon-goods',
        101: 'el-icon-message-solid',
        102: 'el-icon-video-camera-solid',
        145: 'el-icon-s-ticket'
      },
      isCollapse: false,
      path: ''
    }
  },
  methods: {
    toggle () {
      this.isCollapse = !this.isCollapse
    },
    async getMenulist () {
      const res = await MenulistApi()
      console.log(res)
      this.meunlist = res.data
    },
    saveNavState (path) {
      window.sessionStorage.setItem('navState', path)
      this.path = path
    }
  },
  beforeRouteEnter (to, from, next) {
    console.log('sssssssssss');
    next()
  },
  beforeRouteLeave (to, from, next) {
    console.log('在离开组件之前 ');
    next()
  }
}
</script>
<style scoped>
.el-container {
  width: 100%;
  height: 100%;
}
.about {
  width: 100%;
  height: 100%;
  background: #fff;
}
.el-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background-color: #007acc;
  padding-left: 30px;
}

.home {
  display: flex;
  width: 200px;
  height: 50px;
  /* border: 1px solid #000; */
  align-items: center;
}

.el-aside {
  background: #3c3c3c;
}

/* .logo {
  display: flex;
}
img {
  width: 50px;
  height: 50px;
}

.el-aside {
  background: #3c3c3c;
}
.btn {
} */
 .toggle-button{
  background-color: #475163;
  color: #fff;
  font-size: 10px;
  line-height: 24px;
  text-align: center;
  letter-spacing: 0.25em;
  cursor: pointer;
 }
</style>
